<?php

namespace common\models\discount;

use Yii;


/**
 * This is the model class for table "full_cut".
 *
 * @property integer $full_cut_id
 * @property string $title
 * @property integer $c_obj
 * @property integer $c_type
 * @property string $begin_time
 * @property string $end_time
 * @property integer $c_status
 * @property string $create_time
 */
class FullCut extends \yii\db\ActiveRecord
{
    
    public static $STATUS_DESC = [-1=>'请选择',1 => '上线',0=> '下线',];

    public static $STATUS_ONLINE = 1;
    public static $STATUS_INLINE = 0;
    
    public static $OBJ_DESC = [1=>'全场'];
    
    public static $OBJ_ALL = 1;
    
    public static $TYPE_DESC = [1=>'按金额'];
    
    public static $TYPE_BY_AMOUNT = 1;
    
    public $full_cut_set = '';
    
    public $total_amount;//订单消费金额
    
    public $discount_amount;//优惠金额

    public $redis;
    public $redis_key = 'fullcut';

    public function init()
    {
        $this->redis = Yii::$app->redis;
        parent::init();
    }

    public function afterSave($insert, $changedAttributes)
    {
        $this->redis->del($this->redis_key);
        parent::afterSave($insert, $changedAttributes);

    }


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'd_promotion.full_cut';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['title','c_obj','c_type','c_status','begin_time','end_time'],'required'],
            [['c_obj', 'c_type', 'c_status'], 'integer'],
            [['begin_time', 'end_time', 'create_time'], 'safe'],
            [['title'], 'string', 'max' => 50],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'full_cut_id' => 'ID',
            'title' => '活动名称',
            'c_obj' => '满减对象',
            'c_type' => '满减类型',
            'begin_time' => '开始时间',
            'end_time' => '结束时间',
            'c_status' => '状态',
            'create_time' => '创建时间',
            'full_cut_set'=>'满减设置',
        ];
    }
    
    public function getFullCutSe()
    {
        return $this->hasMany(FullCutSet::className(), ['full_cut_id'=>'full_cut_id']);
    }

    public static function shortClassName()
    {
        return (new \ReflectionClass(static::className()))->getShortName();
    }
}
